<template>
	<view class="box">
		<view class="content">
			<view class="card" @click='goDetail(item)' v-for='(item, index) in cardList' :key='index'>
				<image class='img' :src="item.img"></image>
				<p>{{ item.name }}</p>
				<p>{{ item.desc }}</p>
				<p>
					<span>￥{{ item.price }}</span>
					<span>已售{{ item.sellNum }}件</span>
					<image class='img' @click.stop='handleCart(item)' src="@/static/cart/cart.png"></image>
				</p>
			</view>
		</view>
		<view class="finish">
			<span>已加载全部数据</span>
		</view>
	</view>
</template>

<script>
	export default{
		props: ['cardList'],
		methods:{
			// 加入购物车
			handleCart(item){
				this.$store.commit('addCartItem',item)
			},
			// 跳转至详情页
			goDetail(item){
				uni.navigateTo({
					url:'/components/cardItems',
					success(res) {
						res.eventChannel.emit('sendDetail', { data: item })
					}
				})
			}
		},
	}
</script>

<style lang='scss'>
.box{
	width: 100%;
	background-image: linear-gradient(to right bottom,#FFFFFF,#F0F8FF);
	.finish{
		width: 100%;
		height: 70rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-top: 1rpx solid #F1F1F1;
	  color: #C8C7CC;
		font-size: 25rpx;
	}
	.content{
		width: 95%;
		margin-left: 2.5%;
		padding-bottom: 30rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		.card{
			width: 48%;
			border-radius: 15rpx;
			background-color: white;
			margin-top: 30rpx;
			padding-bottom: 10rpx;
			border: 0.3rpx solid rgba(135,206,250,.2);
			>.img{
				width: 100%;
				height: 330rpx;
				border-top-left-radius: 13rpx;
				border-top-right-radius: 13rpx;
			}
			p:first-of-type{
				height: 50rpx;
				line-height: 50rpx;
				font-size: 25rpx;
				padding: 0 6rpx;
				color: #5E5E5E;
				font-family: '微软雅黑';
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
			p:nth-of-type(2){
				height: 55rpx;
				line-height: 55rpx;
				font-size: 25rpx;
				padding: 0 6rpx;
				color: #5E5E5E;
				font-family: '微软雅黑';
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				/* display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical; */
			}
			p:last-of-type{
				padding: 0 6rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				span:first-child{
					color: red;
					font-size: 32rpx;
				}
				span:nth-child(2){
					color: rgba(176,196,222,1);
					font-size: 22rpx;
				}
				.img{
					width: 36rpx;
					height: 36rpx;
					margin-right: 5rpx;
				}
			}
		}
		.card:nth-child(2n){
			margin-left: 2%;
		}
	}
}
</style>
